﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.SharePoint;

namespace SPREST.Models
{
    public class Site
    {
        public string ID { get; set; }
        public string Title { get; set; }

        public static List<Site> GetAllWebs()
        {
            using (SPSite site = new SPSite(ServerConnection.GetServerNameFromConfig()))
            {
                return site.AllWebs.Convert();                
            }
        }

        public static Site GetByID(string id)
        {
            //TODO fix, we don't want to iterate over all webs to find a specific id
            using (SPSite site = new SPSite(ServerConnection.GetServerNameFromConfig()))
            {
                foreach (SPWeb web in site.AllWebs)
                {
                    if (web.ID.ToString() == id)
                    {
                        return web.Convert();
                    }
                }
            }

            return null;
        }
    }
}
